<template>
  <div>
  <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign" :rules="rules" id="form">
    <el-form-item label="文档名称" prop="file">
      <el-input v-model="formLabelAlign.file"></el-input>
    </el-form-item>
    <el-form-item label="单位名称" prop="name">
      <el-input v-model="formLabelAlign.name"></el-input>
    </el-form-item>
    <el-form-item label="单位地点" prop="region">
      <el-input v-model="formLabelAlign.region"></el-input>
    </el-form-item>
    <el-form-item label="填写时间">
        <el-date-picker
                v-model="formLabelAlign.time"
                type="date"
                placeholder="选择日期">
        </el-date-picker>
    </el-form-item>
  </el-form>
    <el-button id="button" type="danger" @click="submitForm">保存基本信息</el-button>
  </div>
</template>

<script>
  import {getMessage} from "../../network/message"
  export default {
    name: "table",
    data() {
      return {
        labelPosition: 'right',
        formLabelAlign: {
          file: '',
          name: '',
          region: '',
          time: ''
        },
        rules: {
          file: [
            { required: true, message: '请输入生成文档名称', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '请输入单位名称', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '请输入单位地点', trigger: 'blur' }
          ],
          time: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ]
        }
      };
    },
    methods: {
      async submitForm() {
        const res=await getMessage(this.formLabelAlign)
        if(res.data.code===200){
          this.$message.success("信息保存成功！")
        }else{
          this.$message.error("信息保存失败！请检查网络连接！")
        }
      }
    }
  }
</script>

<style scoped>
  #form{
    padding-left: 30rem;
    padding-top: 3rem;
    font-weight: bold;
    width: 30rem;
  }
  #button{
    margin-left: 34.5rem;
    width: 25rem;
  }
</style>